<?php
class SocialNetworksTaskFormDecorator extends ATaskFormDecorator{
    public function getFormHTML($params, $view) {
        $html = $this->task_form->getFormHTML($params, $view);
        $this->current_model = new SocialNetworksModel();
        $params['allowed_networks'] = $this->current_model->getAllowedSocialNetworks(); 
        return $html.$view->getCustomer_formbody_step2_socialnetworks($params);
    }

    public function validate_form(&$param, &$scope, $manager) {
        $iserror = false;
        //NETWORK
        $current_model = new SocialNetworksModel();
        $allowed_networks = $current_model->getAllowedSocialNetworks();
        if (empty($param['network_type'])) {
            $iserror = true;
            $manager->addErorrMessageForField("network_type", "Социальная сеть не указана");
        } elseif (!key_exists($param['network_type'], $allowed_networks)) {
            $iserror = true;
            $manager->addErorrMessageForField("network_type", "Недопустимый выбор");
        }
        if ($iserror) {
            return array_merge(array(VALIDATION_FAILED), $this->task_form->validate_form($param, $scope, $manager));
        }
        return array_merge(array(VALIDATION_ACCEPTED), $this->task_form->validate_form($param, $scope, $manager));
    }

    public function submit_form($params, $scope, $manager) {
        $this->task_form->submit_form($params, $scope, $manager);        
    }
}
?>
